package com.sgb.kjwl.view.ui.adapter.enterprise;

import android.content.Context;
import android.util.Log;
import android.view.View;
import android.widget.ImageView;

import com.bumptech.glide.Glide;
import com.sgb.kjwl.BR;
import com.sgb.kjwl.R;
import com.sgb.kjwl.model.entity.enterprise.NeedListItemEntity;
import com.swgk.core.recyclerview.adapter.BaseRecycleAdapter;
import com.swgk.core.recyclerview.adapter.ItemViewHolder;
import com.swgk.core.util.MToast;

import java.util.List;

public class AddNeedListTrandeAdpater extends BaseRecycleAdapter<NeedListItemEntity> {

    private AddNeedListServiceAdpater.ListonclickLister mlister;

    public AddNeedListTrandeAdpater(Context context, List<NeedListItemEntity> datas) {
        super(context, R.layout.item_addneedlist_trande, datas);
    }

    @Override
    public void convert(ItemViewHolder holder, NeedListItemEntity o) {
        holder.setBinding(BR.viewModel, o);

        holder.setText(R.id.tv_need_type, o.getRequirementTypes() == 1 ? "商标需求" : o.getRequirementTypes() == 2 ? "专利需求" :
                o.getRequirementTypes() == 3 ? "版权需求" : o.getRequirementTypes() == 5 ? "服务需求" : "");
        if (o.getOfferStatus() == 1) {
            Glide.with(context).load(R.mipmap.icon_baojiazhong).into((ImageView) holder.getView(R.id.image_state_baojia));
        } else if (o.getOfferStatus() == 2) {
            Glide.with(context).load(R.mipmap.icon_yijieshu).into((ImageView) holder.getView(R.id.image_state_baojia));
        } else if (o.getDemandStatus().equals("-1")) {
            Glide.with(context).load(R.mipmap.icon_yiquxiao).into((ImageView) holder.getView(R.id.image_state_baojia));
        }

        final int position = holder.getIndex_position();
        holder.getItem().findViewById(R.id.btn_check_baojia).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (mlister != null) {
//                    MToast.showToast(context, "该功能正在开发中！");
                    mlister.click(v, position);
                }
            }
        });

        holder.getItem().setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (mlister != null) {
                    Log.e("position", position + "");
                    mlister.click(v, position);
                }
            }
        });

    }

    public void setOnclickLister(AddNeedListServiceAdpater.ListonclickLister lister) {
        mlister = lister;
    }

}
